package com.android.myfirstapps;

import java.util.List;

import android.content.Context;
import android.graphics.Bitmap;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

public class ItemAdapter extends BaseAdapter {
	
	private List<Item> listeItem;
	
	private Context context;
	
	private LayoutInflater inflater;

	public ItemAdapter(Context context, List<Item> listeItem) {
		super();
		this.context = context;
		this.inflater = LayoutInflater.from(context);
		this.listeItem = listeItem;
	}

	public int getCount() {
		return listeItem.size();
	}

	public Object getItem(int position) {
		return listeItem.get(position);
	}

	public long getItemId(int position) {
		return position;
	}

	public View getView(int position, View convertView, ViewGroup parent) {
		LinearLayout layoutItem;
		
		if(convertView == null){
			layoutItem = (LinearLayout) inflater.inflate(R.layout.item, parent, false);
		} else {
			layoutItem = (LinearLayout) convertView;
		}
	
		ImageView image = (ImageView)layoutItem.findViewById(R.id.image);
		TextView titre = (TextView)layoutItem.findViewById(R.id.titre);
		//TextView description = (TextView)layoutItem.findViewById(R.id.description);
		TextView date = (TextView)layoutItem.findViewById(R.id.date);
		
		titre.setText(listeItem.get(position).getTitre());
		//description.setText(listeItem.get(position).getDescription());
		date.setText(listeItem.get(position).getDate());
		image.setImageBitmap(listeItem.get(position).getImage());
		
		return layoutItem;
	}

}
